[GD]txt > png
Auteur: kiwi - 03 maart 2010 - 14:06 - Gekeurd door: Stijn - Hits: 4971 - Aantal punten: 4.00 (3 stemmen)
Het is een simpel scriptje om tekst om te zetten naar een transparante PNG,
het gemakkelijke is als je de link veranderd veranderd de img ook ;D
als je het op een site/forum gewoon tussen de [img] ... [/img] krijg je de afbeelding te zien
je hebt meerdere lettertypen beschikbaar*
je kan de kleur instellen custum en een paar defaults
de breede van de img kan je instellen en is nodig als je voor een lange tekst gaat
de groote word automatisch aangepast naargelang de groote van het lettertype
uitgerust met een error systeem, maar aangezien alleen er een error was voor als je geen tekst invuld (test maar ;D)
* somige tekens werken niet bij alle lettertypes
---------------------------------------------
-[instalatie]-
ALGEMEEN
gewoon de files naar de folder naar keuze.
FONTS:
plaats de fonts (aleen *.tff) in de map "fonts"
dan in de enter_field.php zoek je naar:
<td>Font :</td>
<td><select name="font">
<option value="MASTERPLAN">Masterplan</option>
<option value="SNIPER">Sniper</option>
<option value="Saint-Andrews Queen">Saint-Andrews Queen</option>
<option value="Harabara">Harabara</option>
<option value="Action_of_The_Time_A_L">Action of the time</option>
<option value="bankgothic-regular-db">BankGothic</option>
<option value="evanescent">Evanescent</option>
<option value="Beyond_Wonderland">Beyond wonderland</option>
</select>
</td>
< td> Font :</ td>
< td>< select name= "font" >
< option value= "MASTERPLAN" > Masterplan</ option>
< option value= "SNIPER" > Sniper</ option>
< option value= "Saint-Andrews Queen" > Saint- Andrews Queen</ option>
< option value= "Harabara" > Harabara</ option>
< option value= "Action_of_The_Time_A_L" > Action of the time</ option>
< option value= "bankgothic-regular-db" > BankGothic</ option>
< option value= "evanescent" > Evanescent</ option>
< option value= "Beyond_Wonderland" > Beyond wonderland</ option>
</ select>
</ td>
en daar voeg je ze toe, en bij value vul je de naam in zonder .tff en daarachter hetgeen moet getoond worden in de form
Code:
index.php
<?php
if (isset ($_GET['txt']))
{
header("Content-type: image/png"); //Picture Format
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); //Consitnuously modified
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Pragma: no-cache"); // NO CACHE
if (empty ($_GET['size']))
{
$h = 85;
} else {
$h = $_GET['size'] + 25;
}
if (empty ($_GET['width']))
{
$w = 500;
} else {
$w = $_GET['width'];
}
$bg = imagecreatetruecolor($w, $h);
//This will make it transparent
imagesavealpha($bg, true);
$trans_colour = imagecolorallocatealpha($bg, 255, 0, 0, 127);
imagefill($bg, 0, 0, $trans_colour);
//Text to be written
if (empty ($_GET['txt']))
{
header ("refresh: 0; index.php?e=t");
} else {
$Text = $_GET['txt'];
$Text = stripslashes($Text);
$Text = strip_tags($Text);
$Text = htmlspecialchars ($Text);
}
//Color select
//Default colors
if ( $_GET['color'] != 'custom')
{
$black = imagecolorallocate($bg, 0,0,0);
$white = imagecolorallocate($bg, 255, 255, 255);
$red = imagecolorallocate($bg, 255,0,0);
$grey = imagecolorallocate($bg, 128, 128, 128);
$green = imagecolorallocate($bg, 0,255,0);
$yellow = imagecolorallocate($bg, 255,255,0);
$blue = imagecolorallocate($bg, 0,0,255);
$color = $$_GET['color'];
} else {
if (empty($_GET['red'])) { $red = 0;} else { $red = $_GET['red']; }
if (empty($_GET['green'])) { $green = 0;} else { $green = $_GET['green']; }
if (empty($_GET['blue'])) { $blue = 0;} else { $red = $_GET['blue']; }
$color = imagecolorallocate($bg, $red, $green, $blue);
}
//Select font
$font = 'fonts/'.$_GET['font'].'.ttf';
//Font size
if (empty ($_GET['size']))
{
$fontsize = 60;
} else {
$fontsize = $_GET['size'];
}
$Xpos = $fontsize + 10;
$Ypos = 15;
$Rot = 0;
imagettftext($bg, $fontsize, $Rot, $Ypos, $Xpos, $color, $font, $Text);
//Create image
imagepng($bg);
//destroy image
imagedestroy($bg);
} else {
include ("enter_field.php");
}
?>
<?php
if ( isset ( $_GET [ 'txt' ] ) ) {
header ( "Content-type: image/png" ) ; //Picture Format header ( "Last-Modified: " . gmdate ( "D, d M Y H:i:s" ) . " GMT" ) ; //Consitnuously modified header ( "Cache-Control: no-cache, must-revalidate" ) ; // HTTP/1.1 header ( "Pragma: no-cache" ) ; // NO CACHE
if ( empty ( $_GET [ 'size' ] ) ) {
$h = 85 ;
} else {
$h = $_GET [ 'size' ] + 25 ;
}
if ( empty ( $_GET [ 'width' ] ) ) {
$w = 500 ;
} else {
$w = $_GET [ 'width' ] ;
}
$bg = imagecreatetruecolor( $w , $h ) ;
//This will make it transparent
imagesavealpha( $bg , true ) ;
$trans_colour = imagecolorallocatealpha( $bg , 255 , 0 , 0 , 127 ) ;
imagefill( $bg , 0 , 0 , $trans_colour ) ;
//Text to be written
if ( empty ( $_GET [ 'txt' ] ) ) {
header ( "refresh: 0; index.php?e=t" ) ; } else {
$Text = $_GET [ 'txt' ] ;
}
//Color select
//Default colors
if ( $_GET [ 'color' ] != 'custom' )
{
$black = imagecolorallocate( $bg , 0 , 0 , 0 ) ;
$white = imagecolorallocate( $bg , 255 , 255 , 255 ) ;
$red = imagecolorallocate( $bg , 255 , 0 , 0 ) ;
$grey = imagecolorallocate( $bg , 128 , 128 , 128 ) ;
$green = imagecolorallocate( $bg , 0 , 255 , 0 ) ;
$yellow = imagecolorallocate( $bg , 255 , 255 , 0 ) ;
$blue = imagecolorallocate( $bg , 0 , 0 , 255 ) ;
$color = $$_GET [ 'color' ] ;
} else {
if ( empty ( $_GET [ 'red' ] ) ) { $red = 0 ; } else { $red = $_GET [ 'red' ] ; } if ( empty ( $_GET [ 'green' ] ) ) { $green = 0 ; } else { $green = $_GET [ 'green' ] ; } if ( empty ( $_GET [ 'blue' ] ) ) { $blue = 0 ; } else { $red = $_GET [ 'blue' ] ; }
$color = imagecolorallocate( $bg , $red , $green , $blue ) ;
}
//Select font
$font = 'fonts/' . $_GET [ 'font' ] . '.ttf' ;
//Font size
if ( empty ( $_GET [ 'size' ] ) ) {
$fontsize = 60 ;
} else {
$fontsize = $_GET [ 'size' ] ;
}
$Xpos = $fontsize + 10 ;
$Ypos = 15 ;
$Rot = 0 ;
imagettftext( $bg , $fontsize , $Rot , $Ypos , $Xpos , $color , $font , $Text ) ;
//Create image
imagepng( $bg ) ;
//destroy image
imagedestroy( $bg ) ;
} else {
include ( "enter_field.php" ) ;
}
?>
enter_field.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Img to Png</title>
<style type="text/css">
html{
font-family: Arial, Helvetica, sans-serif;
background-image: url(bg.gif);
color:#FFF;
}
img.header {
border:0px;
}
#enterfield {
position:fixed;
top: 100px;
width: 70%;
left: 15%;
height: 375px;
font-size: 16px;
line-height: 25px;
background-image: url(bg.png);
}
#enterfield.error{
position:fixed;
top: 500px;
width: 70%;
left: 15%;
height: 40px;
background-image: url(bg_red.png);
}
#enterfield.normal{
}
#counter{
position:fixed;
bottom:0;
right:0;
}
#date{
position:fixed;
bottom:0;
left:0;
}
</style>
</head>
<body>
<fieldset id="enterfield" class="normal"><Legend>Make text into an transparant image</legend>
<form action="index.php" method="get">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b><h3>Basic</h3></b></td>
<td> </td>
</tr>
<tr>
<td>Text :</td>
<td><input name="txt" type="text" /></td>
</tr>
<tr>
<td>Font :</td>
<td><select name="font">
<option value="MASTERPLAN">Masterplan</option>
<option value="SNIPER">Sniper</option>
<option value="Saint-Andrews Queen">Saint-Andrews Queen</option>
<option value="Harabara">Harabara</option>
<option value="Action_of_The_Time_A_L">Action of the time</option>
<option value="bankgothic-regular-db">BankGothic</option>
<option value="evanescent">Evanescent</option>
<option value="Beyond_Wonderland">Beyond wonderland</option>
</select>
</td>
</tr>
<tr>
<td>Text-Size :</td>
<td><input name="size" type="text" maxlength="3" size="4" /> (fill in for custom, default = 50)</td>
</tr>
<tr>
<td>Width :</td>
<td><input name="width" type="text" maxlength="4" size="5" /> (fill in for custom, default = 500)</td>
</tr>
<tr>
<td><h3><b>Color:</b></h3></td>
<td> </td>
</tr>
<tr>
<td valign="top"><b>Select:</b><br />
<select name="color">
<option value="black">Black</option>
<option value="white">White</option>
<option value="red">Red</option>
<option value="green">Green</option>
<option value="yellow">Yellow</option>
<option value="blue">Blue</option>
<option value="grey">Grey</option>
<option value="custom">Custom</option>
</select></td>
<td valign="top"><b>Custom:</b><br />
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="75px">
Red :
</td>
<td>
<input name="red" value="0" size="4" maxlength="3" type="text" /><br />
</td>
</tr>
<tr>
<td>
Green :
</td>
<td>
<input name="green" value="0" size="4" maxlength="3" type="text" /><br />
</td>
</tr>
<tr>
<td>
Blue :
</td>
<td>
<input name="blue" value="0" size="4" maxlength="3" type="text" /><br />
</td>
</td>
</tr>
</table>
</td>
</tr>
</table>
<input type="submit" value="Convert">
</legend>
</form>
<?php
if (!empty ($_GET['e']))
{
echo '<fieldset id="enterfield" class="error"><legend>Error</legend>';
$error = $_GET['e'];
switch ($error)
{
case 't':
echo "Please fill in a text.";
break;
}
echo "</fieldset>";
}
?>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns= "http://www.w3.org/1999/xhtml" > <meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" / > html{
font-family: Arial, Helvetica, sans-serif;
background-image: url(bg.gif);
color:#FFF;
}
img.header {
border:0px;
}
#enterfield {
position:fixed;
top: 100px;
width: 70%;
left: 15%;
height: 375px;
font-size: 16px;
line-height: 25px;
background-image: url(bg.png);
}
#enterfield.error{
position:fixed;
top: 500px;
width: 70%;
left: 15%;
height: 40px;
background-image: url(bg_red.png);
}
#enterfield.normal{
}
#counter{
position:fixed;
bottom:0;
right:0;
}
#date{
position:fixed;
bottom:0;
left:0;
}
<form action = "index.php" method = "get" > <table width = "100%" border = "0" cellspacing = "0" cellpadding = "0" > <option value = "Saint-Andrews Queen" > Saint-Andrews Queen
</ option > <option value = "Action_of_The_Time_A_L" > Action of the time
</ option > <option value = "Beyond_Wonderland" > Beyond wonderland
</ option > <td ><input name = "size" type = "text" maxlength = "3" size = "4" / > (fill in for custom, default = 50)
</ td > <td ><input name = "width" type = "text" maxlength = "4" size = "5" / > (fill in for custom, default = 500)
</ td > <td valign = "top" ><b > Select:
</ b ><br / > <td valign = "top" ><b > Custom:
</ b ><br / > <table width = "100%" border = "0" cellspacing = "0" cellpadding = "0" > Red :
<input name = "red" value = "0" size = "4" maxlength = "3" type = "text" / ><br / > Green :
<input name = "green" value = "0" size = "4" maxlength = "3" type = "text" / ><br / > Blue :
<input name = "blue" value = "0" size = "4" maxlength = "3" type = "text" / ><br / > <input type = "submit" value = "Convert" > <?php
if ( !empty ( $_GET[ 'e' ] ) )
{
echo '<fieldset id="enterfield" class="error"><legend> Error
</ legend > ';
$error = $_GET['e'];
switch ($error)
{
case 't':
echo "Please fill in a text.";
break;
}
}
?>
Download code (.txt)
Stemmen
Niet ingelogd.